var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    typeid: 0,
    coll:0,
    oStr:[],
    bool:true,
    show:null,
    content:"",
    show_rent:false,
    // content_buy:"女王购买"
    options_id:null,
    tian:10,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    this.setData({
      typeid: options.order,
      coll: options.ID,
    })
    console.log(this.data.typeid);
    if (this.data.typeid=="1,3"){
      this.setData({
        show:false,
        content:"女王租用"
      })
    }else{
      this.setData({
        show: true,
        content: "女王购买"
      })
    }
    

    // console.log(this.data.typeid);
  },
  // 买
  buy_rent:function(){
    console.log(this.data.content)
    if (this.data.content =="女王租用"){
      if(this.data.show_rent==false){
        this.setData({
          show_rent:true,
        })
      }else{
        return;
      }
    }else{
      var oStr = JSON.stringify(this.data.oStr);
      wx.navigateTo({
        url: '/pages/index/Make/Make?id=' + this.data.oStr.goodsId + "&oID=" + this.data.typeid,
      })
    }
  },
  // 租
  rent_ok: function () {
    wx.request({
      url: app.globalData.url + 'index.php/Api/User/myYa',
      data: {
        userId: 16,
        token: 1501221705,
      },
      success: (res) => {
        console.log(res);
        if (res.data.resultObj == "0" || res.data.resultObj == 0) {
          wx.showModal({
            title: '提示',
            content: '请缴纳押金',
          })
        } else {
          console.log(this.data.typeid);
          console.log(this.data.oStr.goodsId);
          wx.navigateTo({
            url: '/pages/index/Make/Make?id=' + this.data.oStr.goodsId + "&oID=" + this.data.typeid,
          })
        }
      }
    })
  },
  back_f:function(){
    if(this.data.show_rent==true){
      this.setData({
        show_rent:false,
      })
    }else{
      return;
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
    // wx.request({
    //   url: 'https://bag.idianwei.com/index.php/Api/Api/repackInfo',
    //   // method: "POST", 
    //   data: {
    //     collectType: this.data.typeid,
    //     goodsId: this.data.coll,
    //     userId: 16,
    //   },
       
    //   success: res => {
    //     console.log(res);
    //     // var arr=JSON.parse(res.data);
    //     // console.log(arr);
    //     // this.setData({
    //     //   oStr: arr
    //     // })
    //   }
    // })

    wx:wx.request({
      url: 'https://bag.idianwei.com/index.php/Api/Api/repackList',
      data: {},
      success:(res)=>{
        console.log(res);
        for (var i = 0; i < res.data.resultObj.length;i++){
          if (res.data.resultObj[i].goodsId == this.data.coll){
            this.setData({
              oStr: res.data.resultObj[i],
            })
          }
        }
        console.log(this.data.oStr);
      }
    })


  },
  love:function(){
    var shou = "index.php/Api/User/repackCollection";
    var qu = "index.php/Api/User/delCollection";
    var cang;
    if(this.data.bool==true){
      cang=shou;
    }else{
      cang=qu;
    }
    wx.request({
      url: "https://bag.idianwei.com/" + cang,
      data:{
        userId: 16,
        token: 1501221705,
        collectType: this.data.typeid,
        goodsId: this.data.coll,
      },
      success:(res)=>{
        console.log(res);
        if (cang =="index.php/Api/User/repackCollection"){
          wx.showModal({
            title: '提示',
            content: '已加成功入心愿单',
          });
          this.setData({
            bool:false,
          });
          return;
        } else if (cang == "index.php/Api/User/delCollection"){
          wx.showModal({
            title: '提示',
            content: '已从心愿单移除该商品',
          });
          this.setData({
            bool: true,
          });
          return;
        }
      }
    })
  },
  // 购物车
  add:function(){
    wx.request({
      url: "https://bag.idianwei.com/index.php/Api/Api/addCart",
      data: {
        userId: 16,
        token: 1501221705,
        goodsId: this.data.coll,
      },
      success: (res) => {
        console.log(res);
      }
    })
  },
  
  
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})